/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.worsik.vypocty.topeni.tepelneztraty.view.mistnosti;

import java.awt.Point;
import java.awt.event.MouseEvent;
import javax.swing.JTable;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;

/**
 *
 * @author 231260
 */
class TTHeader extends JTableHeader
{
	// The following String array holds all ToolTip text, with one entry
	// for each table column. If a column is to display default ToolTip
	// text, the corresponding entry is "".

	private String [] allToolTipsText;

	TTHeader (TableColumnModel tcm)
	{
		// Pass the TableColumnModel object to the superclass, which 
		// takes care of that object.

		super (tcm);
	}

	// The following method is automatically called when the mouse 
	// cursor hotspot moves over any one of the header rectangles in a
	// table header.

	@Override
	public String getToolTipText (MouseEvent e)
	{
		// Return the pixel position of the mouse cursor hotspot.

		Point p = e.getPoint ();

		// Convert the pixel position to the zero-based column index of
		// the table header column over which the mouse cursor hotspot is
		// located. The result is a view-based column index.

		int viewColumnIndex = columnAtPoint (p);

		// Retrieve a reference to the JTable object associated with the
		// table header.

		JTable jt = getTable ();

		// Convert the view-based column index to a model-based column
		// index.

		int modelColumnIndex = 
		jt.convertColumnIndexToModel (viewColumnIndex);

		// If model's ToolTip text is not present in allToolTipsText, 
		// that means the default ToolTip text should be returned. 
		// Otherwise, return the actual ToolTip text.

		if (allToolTipsText [modelColumnIndex].length () == 0)
			return super.getToolTipText (e);
		else
			return allToolTipsText [modelColumnIndex];
	}

	void setToolTipsText (String [] myToolTipsText)
	{
		// Save the ToolTips text array for use by getToolTipText().

		allToolTipsText = myToolTipsText;
	}
}
